package ihooyah.com.whitehat

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import ihooyah.com.whitehat.dao.clearDao
import ihooyah.com.whitehat.utils.*
import kotlinx.android.synthetic.main.activity_map.*

/**
 * Created by debby on 2019/1/4.
 * 描述:
 */
class MapActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_map)
        initView()
    }

    private fun initView() {
        initData()
    }

    private fun initData() {
        ivLocation.setOnClickListener { location() }


        btSetting.setOnClickListener {
            val pairList = ArrayList<Pair<String, OnButtonClickListener>>()
            //添加子项目
            pairList.add(Pair("显示轨迹", OnButtonClickListener {
                showTrajectoryList(map.map)
            }))
            pairList.add(Pair("清除数据库", OnButtonClickListener {
                showSimpleAlert(this, "是否清除数据库？") {
                    clearDao()
                }
            }))


            //展示list
            showButtonList(this, pairList)
        }

    }


    private fun location(){
        val hyLocationUtil = HYLocationUtil(this)
        hyLocationUtil.startLocation { bdLocation ->
            locationTo(bdLocation, map.map)
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        map.onDestroy()
    }

    override fun onPause() {
        super.onPause()
        map.onPause()
    }

    override fun onResume() {
        super.onResume()
        map.onResume()
    }


}